<template>
  <div class="data-table">
    <header>
      <div>
        <svg-icon icon-class="dashboard-2"></svg-icon
        ><span style="padding-left: 8px">分组加热时长详情</span>
      </div>
      <div class="data-table-close" @click="$emit('onClose')">
        <i class="el-icon-close"></i>
      </div>
    </header>
    <main>
      <div class="data-main-head">所有分组能耗数据</div>
      <el-table
        :data="tableData"
        style="width: 100%"
        row-class-name="data-table-row"
        cell-class-name="data-table-cell"
        header-row-class-name="data-table-header-row"
        header-cell-class-name="data-table-header-cell"
        tooltip-effect="dark"
      >
        <el-table-column
          v-for="(item, index) in tableHeader"
          :key="index"
          :prop="item.prop"
          :label="item.label"
          :show-overflow-tooltip="true"
        >
          <template #default="scope">
            <div
              v-if="item.prop === 'date'"
              style="color: #818cf8; font-weight: 600; font-size: 14px"
            >
              {{ scope.row.date }}
            </div>
            <div v-else-if="item.prop === 'change'" style="color: #10b981">
              {{ scope.row.change }}
            </div>
            <div v-else-if="item.prop === 'sex'" style="color: #10b981">
              {{ scope.row.sex }}
            </div>
            <div v-else>{{ scope.row[item.prop] }}{{ scope.row.label }}</div>
          </template>
        </el-table-column>
      </el-table>

      <div class="data-foot-page">
        <el-pagination
          ref="paginationRef"
          @current-change="handleCurrentChange"
          :current-page.sync="currentPage"
          :page-sizes="[100, 200, 300, 400]"
          :page-size="20"
          layout="total,prev, pager, next, jumper"
          :total="1000"
          :background="true"
          popper-class="data-table-pagination"
          :popper-append-to-body="true"
        >
        </el-pagination>
      </div>
    </main>
    <footer>
      <div class="btn-primary">
        <i
          class="el-icon-download"
          style="font-weight: 900; padding-right: 5px"
        ></i
        >导出数据
      </div>
      <div class="btn-secondary" @click="$emit('onClose')">
        <i
          class="el-icon-close"
          style="font-weight: 900; padding-right: 5px"
        ></i
        >关闭
      </div>
    </footer>
  </div>
</template>
<script>
export default {
  name: "DataTable",
  data() {
    return {
      tableData: [
        {
          date: "商业中心区",
          name: "28,540",
          address: "856,200",
          sex: "+25.2%",
          change: "+2.1%",
        },
        {
          date: "商业中心区",
          name: "28,540",
          address: "856,200",
          sex: "+25.2%",
          change: "+2.1%",
        },
        {
          date: "商业中心区",
          name: "28,540",
          address: "856,200",
          sex: "+25.2%",
          change: "+2.1%",
        },
        {
          date: "商业中心区",
          name: "28,540",
          address: "856,200",
          sex: "+25.2%",
          change: "+2.1%",
        },
        {
          date: "商业中心区",
          name: "28,540",
          address: "856,200",
          sex: "+25.2%",
          change: "+2.1%",
        },
        {
          date: "商业中心区",
          name: "28,540",
          address: "856,200",
          sex: "+25.2%",
          change: "+2.1%",
        },
        {
          date: "商业中心区",
          name: "28,540",
          address: "856,200",
          sex: "+25.2%",
          change: "+2.1%",
        },
        {
          date: "商业中心区",
          name: "28,540",
          address: "856,200",
          sex: "+25.2%",
          change: "+2.1%",
        },
        {
          date: "商业中心区",
          name: "28,540",
          address: "856,200",
          sex: "+25.2%",
          change: "+2.1%",
        },
        {
          date: "商业中心区",
          name: "28,540",
          address: "856,200",
          sex: "+25.2%",
          change: "+2.1%",
        },
      ],
      currentPage: 1,
      tableHeader: [
        {
          prop: "date",
          label: "分组名称",
        },
        {
          prop: "name",
          label: "今日能耗",
        },
        {
          prop: "address",
          label: "本月能耗",
        },
        {
          prop: "sex",
          label: "同比变化",
        },
        {
          prop: "change",
          label: "环比变化",
        },
      ],
    };
  },
  mounted() {
    // this.fixPaginationDropdown();
  },
  updated() {
    // this.fixPaginationDropdown();
  },
  methods: {
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
    },
    fixPaginationDropdownStyle() {
      this.$nextTick(() => {
        // 只修复样式，不修改 prop
        const dropdowns = document.querySelectorAll(".data-table-pagination");
        dropdowns.forEach((dropdown) => {
          // 强制设置样式确保在全屏模式下可见
          dropdown.style.setProperty("position", "fixed", "important");
          dropdown.style.setProperty("z-index", "999999", "important");
        });
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.data-table {
  color: #fff;
}
.data-table header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 20px;
  font-weight: bold;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(59, 130, 246, 0.2);
  .data-table-close {
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 16px;
    width: 26px;
    height: 26px;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    background-color: transparent;
    border-radius: 50%;
  }
  .data-table-close:hover {
    background-color: rgba(35, 43, 57, 0.8);
  }
}
.data-table main {
  max-height: 70vh;
  .data-main-head {
    margin: 18px 0;
    font-size: 16px;
    font-weight: bold;
  }
  .data-foot-page {
    margin: 16px 0;
  }
}
.data-table footer {
  padding-top: 15px;
  border-top: 1px solid rgba(59, 130, 246, 0.2);
  display: flex;
  justify-content: flex-end;
}
.data-table footer > div {
  padding: 8px 12px;
  cursor: pointer;
  margin-left: 8px;
  border-radius: 6px;
  transition: all 0.2s ease-in-out;
}
.data-table footer > div:hover {
  transform: translateY(-2px); /* 增加位移量使效果更明显 */
  box-shadow: 0 2px 8px rgba(255, 255, 255, 0.1); /* 添加阴影增强效果 */
}
.btn-secondary {
  background-color: #4f46e5;
}
.btn-primary {
  background-color: rgba(255, 255, 255, 0.1);
}
</style>
<style lang="scss">
.data-table main {
  // 表格样式
  .el-table,
  .el-table tr,
  .data-table-row {
    background-color: transparent;
    color: #cbd5e1;
    font-weight: bold;
    font-size: 14px;
  }
  .el-table__header-wrapper {
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
  }
  .el-table th.el-table__cell {
    background-color: rgba(59, 130, 246, 0.2);
    border-bottom: 1px solid rgba(59, 130, 246, 0.2);
    color: #fff;
  }
  .el-table::before,
  .el-table--group::after,
  .el-table--border::after {
    content: "";
    position: absolute;
    background-color: rgba(255, 255, 255, 0.05);
    z-index: 1;
  }
  .data-table-row .data-table-cell {
    background-color: transparent;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    color: #cbd5e1;
    font-weight: normal;
    font-size: 12px;
  }
  .data-table-row:hover,
  .data-table-row:hover .data-table-cell,
  .el-table--enable-row-hover .el-table__body tr:hover > td.el-table__cell {
    background: #232b39 !important;
  }

  // 分页样式
  .el-pagination__total,
  .el-pagination__jump {
    color: #cbd5e1;
  }

  .el-pagination__sizes .el-input .el-input__inner:hover,
  .el-pagination__editor.el-input .el-input__inner:hover,
  .el-pagination.is-background .el-pager li:not(.disabled):hover {
    border-width: 2px;
    color: #fff;
  }
  .el-pagination__sizes .el-input .el-input__inner,
  .el-pagination__editor.el-input .el-input__inner,
  .el-pagination.is-background .btn-prev,
  .el-pagination.is-background .btn-next,
  .el-pagination.is-background .el-pager li {
    background-color: transparent;
    border: 1px solid rgba(59, 130, 246, 0.2);
    color: #cbd5e1;
  }
  .el-pagination.is-background .el-pager li:not(.disabled).active {
    background-color: rgba(59, 130, 246, 0.2);
    color: #ffffff;
    border-color: transparent;
  }
}

// 关键修改：使用更强制的CSS规则确保下拉框显示
.el-select-dropdown.data-table-pagination {
  background-color: #1e293b !important;
  border: 1px solid rgba(59, 130, 246, 0.3) !important;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.3) !important;
  z-index: 999999 !important;
  position: fixed !important;
  :fullscreen &,
  :-webkit-full-screen &,
  :-moz-full-screen &,
  :-ms-fullscreen & {
    position: fixed !important;
    z-index: 999999 !important;
  }
}

// 针对各种全屏状态的特殊处理
*:fullscreen .el-select-dropdown.data-table-pagination,
*:-webkit-full-screen .el-select-dropdown.data-table-pagination,
*:-moz-full-screen .el-select-dropdown.data-table-pagination,
*:-ms-fullscreen .el-select-dropdown.data-table-pagination {
  position: fixed !important;
  z-index: 999999 !important;
}

// 确保在任何上下文中都有足够高的层级
.el-select-dropdown.data-table-pagination {
  z-index: 999999 !important;

  // 强制覆盖所有可能的定位上下文
  &[style*="position"] {
    position: fixed !important;
  }
}

// 针对 Element UI 的特殊处理
.el-popper[data-popper-placement] {
  &[class*="data-table-pagination"] {
    z-index: 999999 !important;
    position: fixed !important;
  }
}
</style>
